package com.geekaca.d4.d3;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.MonthDay;

public class TestUpdateDateTime {
    public static void main(String[] args) {
//        updateDate();
//        beforeAfter();
        /**
         * 构造一个日期时间对象
         * 指向月中的第几天
         */
        LocalDateTime localDateTime = LocalDateTime.now();
        LocalDateTime localDateTime1 = localDateTime.withDayOfMonth(23);
        System.out.println(localDateTime1);
//        LocalDateTime localDateTime2 = localDateTime.withDayOfMonth(49);
//        System.out.println(localDateTime2);

        LocalDateTime localDateTime3 = LocalDateTime.of(2023,11,22,11,45,30);
        System.out.println("localDateTime3 = " + localDateTime3);
    }

    public static void updateDate() {
        //不可变对象, 时间值不可改变
        LocalDate now = LocalDate.now();

        LocalDate newDate = now.plusYears(20);
    }

    public static void panduan() {
        LocalDate myBir = LocalDate.of(1980, 5, 4);
        LocalDate now = LocalDate.now();
        boolean isMybir = now.equals(myBir);
        System.out.println("今天是否是你的生日: " + isMybir);
    }

    // 判数日期是否在某个日期的前还是后
    public static void beforeAfter() {
        LocalDate myDate = LocalDate.of(2023, 12, 12);
        LocalDate nowDate = LocalDate.now();
        // 今天是否是2023-12-12 计划在某个时间做什么事情,做一个提醒
        boolean isTheDate = nowDate.equals(myDate);
        System.out.println("今天是否是2023-12-12: " + isTheDate);

        System.out.println(myDate.isBefore(nowDate));
        System.out.println(myDate.isAfter(nowDate));

        //判断今天是否是你的生日
        LocalDate birthDay = LocalDate.of(1983, 11, 26);
        LocalDate nowDate2 = LocalDate.now();

        MonthDay myBirth = MonthDay.of(birthDay.getMonth().getValue(), birthDay.getDayOfMonth());
        MonthDay nowMonthDay = MonthDay.of(nowDate2.getMonthValue(), nowDate2.getDayOfMonth());
        System.out.println("今天" + (myBirth.equals(nowMonthDay) ? "是" : "不是") + "你的生日");


    }

    public void updateDateTime() {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime newTime = now.plusDays(52);
        System.out.println(newTime);

        LocalDateTime newTime2 = now.plusHours(45);
        System.out.println(newTime2);
    }
}
